package com.atguigu.Controller;

import com.atguigu.Serivce.DishFlavorService;
import com.atguigu.Serivce.DishService;
import com.atguigu.Utils.R;
import com.atguigu.pojo.Dish;
import com.atguigu.pojo.Dto.DishDto;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * 对于菜品与菜品口味的处理
 */

@RestController
@RequestMapping("dish")
public class DishController {

    private static final Logger log = LoggerFactory.getLogger(DishController.class);
    @Autowired
    private DishService dishService;


    @PostMapping
    public R addDish(@RequestBody DishDto dishDto) {

        return dishService.addDishAndFlavor(dishDto);
    }

    @GetMapping("page")
    public R getDishPage(Integer page,Integer pageSize,String name) {
        return dishService.page(page,pageSize,name);
    }

    @GetMapping("{id}")
    public R reShow(@PathVariable Long id) {
        return dishService.reShow(id);
    }

    @PutMapping
    public R updateDish(@RequestBody DishDto dishDto) {
        return dishService.updateDish(dishDto);
    }

    @PostMapping("status/{id}")//id应该是要调整为的状态,0是停售，1是启售
    public R updateDish(@PathVariable Long id,Long[]ids ) {
        return dishService.updateStatus(id,ids);
    }

    @DeleteMapping
    public R deleteDish( Long[] ids) {
        return dishService.delereDish(ids);
    }

    @GetMapping("/list")
    public R listDish(Long categoryId) {
            return dishService.listDish(categoryId);
    }

}
